package com.dogdog.adapter;

import java.util.List;

import com.baidu.location.a.h;
import com.dogdog.UI.RoundedImageView;
import com.dogdog.activity.R;
import com.dogdog.bean.RoundUserInfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class RoundUserAdapter extends BaseAdapter{
	private Context context;
	private List<RoundUserInfo> roundUserInfo;
	private LayoutInflater inflater;
	
	public RoundUserAdapter() {
		// TODO Auto-generated constructor stub
	}
	public RoundUserAdapter(Context context,List<RoundUserInfo> roundUserInfos){
		this.context=context;
		this.roundUserInfo=roundUserInfos;
		inflater=LayoutInflater.from(context);
	}
	
	
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return roundUserInfo.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return roundUserInfo.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		RoundUserInfo roundUserInfo=new RoundUserInfo();
		ViewHolder holder=null;
		if (convertView!=null) {
			holder= (ViewHolder) convertView.getTag();
		}else{
			holder=new ViewHolder();
			convertView=inflater.inflate(R.layout.item_rounduser_list, null);
			holder.tv_userName=(TextView)convertView.findViewById(R.id.tv_userName);
			holder.tv_petKind=(TextView)convertView.findViewById(R.id.tv_dogKind);
			holder.tv_petName=(TextView)convertView.findViewById(R.id.tv_dogName);
			holder.tv_petAge=(TextView)convertView.findViewById(R.id.tv_dogAge);
			holder.tv_distance=(TextView)convertView.findViewById(R.id.tv_distance);
			holder.iv_avatar=(RoundedImageView)convertView.findViewById(R.id.iv_avatar);
			convertView.setTag(holder);
		}
		holder.tv_userName.setText(roundUserInfo.getUser_name());
		holder.tv_petKind.setText(roundUserInfo.getPet_kind());;
		holder.tv_petName.setText(roundUserInfo.getPet_name());;
		holder.tv_petAge.setText(roundUserInfo.getPet_age());;
		holder.tv_distance.setText(roundUserInfo.getDistance()+"");;
		holder.iv_avatar.setImageBitmap(roundUserInfo.getUser_face());;
		
		return convertView;
	}
	

	static class ViewHolder{
		TextView tv_userName;
		TextView tv_petKind;
		TextView tv_petName;
		TextView tv_petAge;
		TextView tv_distance;
		RoundedImageView iv_avatar;
	}
}
